<html>
<head>
<style type='text/css'>
body {
   background-color: white;
   margin: 1em 2em 1em 2em;
   font-family: Sans-Serif;
   color: #002;
   line-height: 140%;
   font-size: 12px;
}

h1 {
    font-size: 140%;
}

h2 {
    font-size: 130%;
}

h3 {
    font-size: 120%;
}

h4 {
    font-size: 100%;
    font-style: normal;
    font-weight: bold;
}

h5 {
    font-size: 100%;
    font-style: italic;
    font-weight: normal;
}

pre {
   background-color: #eee;
   padding: 0.5em 0.5em 0.5em 2em;
}

@media print {
   pre {word-wrap:break-word; width:100%;}
} 

ul li,
ol li {
   padding-left: 0.3em;
   /*text-indent: -2em;*/
   margin-bottom: 0.5em;
}

em {
   font-style: normal;
   font-weight: bold;
   text-decoration: underline;
   color: #c40;
}

code {
   font-family: Monospace;
   font-size: 100%;
   color: #c40;
}

a, a * {
   text-decoration: underline;
   color: #14a0d1;
   /* border: 0.5px solid #aaa;
   white-space: nowrap;
   padding-right: 0.1em;
   padding-left: 0.1em;
   padding-bottom: -5px; */
}

a code {
   color: #14a0d1;
}

img {
   position: relative;
   bottom: -4px;
}

div.headline {
   font-weight: bold;
   font-size: 110%;
}

div.copyright {
   margin-top: 1em;
   border-top: 1px solid black;
   padding-top: 0.5em;
}

div.iris_headline {
   border-bottom: 1px solid black;
   padding-bottom: 0.3em;
}

.LaTeX {
   font-family: Monospace;
   font-size: 100%;
   border: 1px solid #060;
   color: #060;
}

code.LaTeX {
   background-color: white;
   padding: 0.5em 0.5em 0.5em 2em;
}
</style>
</head>

<body>
<div class="iris_headline">IRIS Toolbox Reference Manual</div>




<h2 id="model/simulate">simulate</h2>
<div class="headline">Simulate model</div>

<h4 id="syntax">Syntax</h4>
<pre><code>S = simulate(M,D,Range,...)
[S,Flag,AddF,Delta] = simulate(M,D,Range,...)</code></pre>
<h4 id="input-arguments">Input arguments</h4>
<ul>
<li><p><code>M</code> [ model ] - Solved model object.</p></li>
<li><p><code>D</code> [ struct | cell ] - Input database or datapack from which the initial conditions and shocks from within the simulation range will be read.</p></li>
<li><p><code>Range</code> [ numeric | char ] - Simulation range.</p></li>
</ul>
<h4 id="output-arguments">Output arguments</h4>
<ul>
<li><code>S</code> [ struct | cell ] - Database with simulation results.</li>
</ul>
<h4 id="output-arguments-in-nonlinear-simulations">Output arguments in nonlinear simulations</h4>
<ul>
<li><p><code>ExitFlag</code> [ cell | empty ] - Cell array with exit flags for nonlinearised simulations.</p></li>
<li><p><code>AddF</code> [ cell | empty ] - Cell array of tseries with final add-factors added to first-order approximate equations to make nonlinear equations hold.</p></li>
<li><p><code>Delta</code> [ cell | empty ] - Cell array of tseries with final discrepancies between LHS and RHS in equations marked for nonlinear simulations by a double-equal sign.</p></li>
</ul>
<h4 id="options">Options</h4>
<ul>
<li><p><code>'anticipate='</code> [ <em><code>true</code></em> | <code>false</code> ] - If <code>true</code>, real future shocks are anticipated, imaginary are unanticipated; vice versa if <code>false</code>.</p></li>
<li><p><code>'contributions='</code> [ <code>true</code> | <em><code>false</code></em> ] - Decompose the simulated paths into contributions of individual shocks.</p></li>
<li><p><code>'dbOverlay='</code> [ <code>true</code> | <em><code>false</code></em> | struct ] - Use the function <code>dboverlay</code> to combine the simulated output data with the input database, (or a user-supplied database); both the data preceeding the simulation range and after the simulation range are appended.</p></li>
<li><p><code>'deviation='</code> [ <code>true</code> | <em><code>false</code></em> ] - Treat input and output data as deviations from balanced-growth path.</p></li>
<li><p><code>'dTrends='</code> [ <em><code>@auto</code></em> | <code>true</code> | <code>false</code> ] - Add deterministic trends to measurement variables.</p></li>
<li><p><code>'ignoreShocks='</code> [ <code>true</code> | <em><code>false</code></em> ] - Read only initial conditions from input data, and ignore any shocks within the simulation range.</p></li>
<li><p><code>'method='</code> [ <em><code>'firstorder'</code></em> | <code>'selective'</code> | <code>'global'</code> ] - Method of running simulations; <code>'firstorder'</code> means first-order approximate solution (calculated around steady state); <code>'selective'</code> means equation-selective nonlinear method; <code>'global'</code> means global nonlinear method (available only in models with no leads).</p></li>
<li><p><code>'plan='</code> [ plan ] - Specify a simulation plan to swap endogeneity and exogeneity of some variables and shocks temporarily, and/or to simulate some nonlinear equations.</p></li>
<li><p><code>'progress='</code> [ <code>true</code> | <em><code>false</code></em> ] - Display progress bar in the command window.</p></li>
<li><p><code>'sparseShocks='</code> [ <code>true</code> | <em><code>false</code></em> ] - Store anticipated shocks (including endogenized anticipated shocks) in sparse array.</p></li>
</ul>
<h4 id="options-for-equation-selective-nonlinear-simulations">Options for equation-selective nonlinear simulations</h4>
<ul>
<li><p><code>'solver='</code> [ <em><code>@qad</code></em> | <code>@fsolve</code> | <code>@lsqnonlin</code> ] - Solution algorithm; see Description.</p></li>
<li><p><code>'maxNumelJv='</code> [ numeric | <em><code>1e6</code></em> ] - Maximum number of data points (nonlinear plus exogenized) allowed for a nonrecursive algorithm in the nonlinear equation updating step; if exceeded, a recursive (period-by-period) simulation is used to update nonlinear equations instead.</p></li>
<li><p><code>'nonlinPer='</code> [ numeric | <em><code>@all</code></em> ] - Horizon (number of periods from the beginning of the simulation, and from the beginning of each simulation segment) over which nonlinearities will be preserved; the remaining periods will be simulated using first-order approximate solution.</p></li>
</ul>
<h4 id="options-for-equation-selective-nonlinear-simulations-with-qad-solver">Options for equation-selective nonlinear simulations with <span class="citation">@qad</span> solver</h4>
<ul>
<li><p><code>'addSstate='</code> [ <em><code>true</code></em> | <code>false</code> ] - Add steady state levels to simulated paths before evaluating nonlinear equations; this option is used only if <code>'deviation=' true</code>.</p></li>
<li><p><code>'display='</code> [ <em><code>true</code></em> | <code>false</code> | numeric | Inf ] - Report iterations on the screen; if <code>'display=' N</code>, report every <code>N</code> iterations; if <code>'display=' Inf</code>, report only final iteration.</p></li>
<li><p><code>'error='</code> [ <code>true</code> | <em><code>false</code></em> ] - Throw an error whenever a nonlinear simulation fails converge; if <code>false</code>, only an warning will display.</p></li>
<li><p><code>'lambda='</code> [ numeric | <em><code>1</code></em> ] - Initial step size (between <code>0</code> and <code>1</code>) for add factors added to nonlinearised equations in every iteration; see also <code>'nOptimLambda='</code>.</p></li>
<li><p><code>'nOptimLambda='</code> [ numeric | <code>false</code> | <em><code>1</code></em> ] - Find the optimal step size on a grid of 10 points between 0 and <code>'lambda='</code> before each of the first <code>'nOptimLambda='</code> iterations; if <code>false</code>, the value assigned to <code>Lambda</code> is used and no grid search is performed.</p></li>
<li><p><code>'reduceLambda='</code> [ numeric | <em><code>0.5</code></em> ] - Reduction factor (between <code>0</code> and <code>1</code>) by which <code>lambda</code> will be multiplied if the nonlinear simulation gets on an divergence path.</p></li>
<li><p><code>'upperBound='</code> [ numeric | <em><code>1.5</code></em> ] - Multiple of all-iteration minimum achieved that triggers a reversion to that iteration and a reduciton in <code>lambda</code>.</p></li>
<li><p><code>'maxIter='</code> [ numeric | <em><code>100</code></em> ] - Maximum number of iterations.</p></li>
<li><p><code>'tolerance='</code> [ numeric | <em><code>1e-5</code></em> ] - Convergence tolerance.</p></li>
</ul>
<h4 id="options-for-nonlinear-simulations-with-optim-tbx-solver">Options for nonlinear simulations with Optim Tbx solver</h4>
<ul>
<li><code>'optimSet='</code> [ cell | struct ] - Optimization Tbx options.</li>
</ul>
<h4 id="options-for-global-nonlinear-simulations">Options for global nonlinear simulations</h4>
<ul>
<li><p><code>'optimSet='</code> [ cell | struct ] - Optimization Tbx options.</p></li>
<li><p><code>'solver='</code> [ <code>@fsolve</code> | <em><code>@lsqnonlin</code></em> ] - Solution algorithm; see Description.</p></li>
</ul>
<h4 id="description">Description</h4>
<p>The function <code>simulate(...)</code> simulates a model on the specified simulation range. By default, the simulation is based on a first-order approximate solution (calculated around steady state). To run nonlinear simulations, use the option <code>'nonlinear='</code> (to set the number of periods</p>
<h5 id="output-range">Output range</h5>
<p>Time series in the output database, <code>S</code>, are are defined on the simulation range, <code>Range</code>, plus include all necessary initial conditions, ie. lags of variables that occur in the model code. You can use the option <code>'dboverlay='</code> to combine the output database with the input database (ie. to include a longer history of data in the simulated series).</p>
<h5 id="deviations-from-steady-state-and-deterministic-trends">Deviations from steady-state and deterministic trends</h5>
<p>By default, both the input database, <code>D</code>, and the output database, <code>S</code>, are in full levels and the simulated paths for measurement variables include the effect of deterministic trends, including possibly exogenous variables. The default behavior can be changed by changing the options <code>'deviation='</code> and <code>'dTrends='</code>.</p>
<p>The default value for <code>'deviation='</code> is false. If set to <code>true</code>, then the input database is expected to contain data in the form of deviations from their steady state levels or paths. For ordinary variables (ie. variables whose log status is <code>false</code>), it is <span class="LaTeX">$x_t-\Bar x_t$</span>, meaning that a 0 indicates that the variable is at its steady state and e.g. 2 indicates the variables exceeds its steady state by 2. For log variables (ie. variables whose log status is <code>true</code>), it is <span class="LaTeX">$x_t/\Bar x_t$</span>, meaning that a 1 indicates that the variable is at its steady state and e.g. 1.05 indicates that the variable is 5 per cent above its steady state.</p>
<p>The default value for <code>'dTrends='</code> is <code>@auto</code>. This means that its behavior depends on the option <code>'deviation='</code>. If <code>'deviation=' false</code> then deterministic trends are added to measurement variables, unless you manually override this behavior by setting <code>'dTrends=' false</code>. On the other hand, if <code>'deviation=' true</code> then deterministic trends are not added to measurement variables, unless you manually override this behavior by setting <code>'dTrends=' true</code>.</p>
<h5 id="simulating-contributions-of-shocks">Simulating contributions of shocks</h5>
<p>Use the option <code>'contributions=' true</code> to request the contributions of shocks to the simulated path for each variable; this option cannot be used in models with multiple alternative parameterizations or with multiple input data sets.</p>
<p>The output database, <code>S</code>, contains Ne+2 columns for each variable, where Ne is the number of shocks in the model:</p>
<ul>
<li><p>the first columns 1...Ne are the contributions of the Ne individual shocks to the respective variable;</p></li>
<li><p>column Ne+1 is the contribution of initial condition, th econstant, and deterministic trends, including possibly exogenous variables;</p></li>
<li><p>column Ne+2 is the contribution of nonlinearities in nonlinear simulations (it is always zero otherwise).</p></li>
</ul>
<p>The contributions are additive for ordinary variables (ie. variables whose log status is <code>false</code>), and multplicative for log variables (ie. variables whose log status is <code>true</code>). In other words, if <code>S</code> is the output database from a simulation with <code>'contributions=' true</code>, <code>X</code> is an ordinary variable, and <code>Z</code> is a log variable, then</p>
<pre><code>sum(S.X,2)</code></pre>
<p>(ie. the sum of all Ne+2 contributions in each period, ie. summation goes across 2nd dimension) reproduces the final simulated path for the variable <code>X</code>, whereas</p>
<pre><code>prod(S.Z,2)</code></pre>
<p>(ie. the product of all Ne+2 contributions) reproduces the final simulated path for the variable <code>Z</code>.</p>
<h5 id="simulations-with-multiple-parameterisations-andor-multiple-data-sets">Simulations with multiple parameterisations and/or multiple data sets</h5>
<p>If you simulate a model with <code>N</code> parameterisations and the input database contains <code>K</code> data sets (ie. each variable is a time series with <code>K</code> columns), then the following happens:</p>
<ul>
<li><p>The model will be simulated a total of <code>P = max(N,K)</code> number of times. This means that each variables in the output database will have <code>P</code> columns.</p></li>
<li><p>The 1st parameterisation will be simulated using the 1st data set, the 2nd parameterisation will be simulated using the 2nd data set, etc. until you reach either the last parameterisation or the last data set, ie. <code>min(N,K)</code>. From that point on, the last parameterisation or the last data set will be simply repeated (re-used) in the remaining simulations.</p></li>
<li><p>Formally, the <code>I</code>-th column in the output database, where <code>I = 1, ..., P</code>, is a simulation of the <code>min(I,N)</code>-th model parameterisation using the <code>min(I,K)</code>-th input data set number.</p></li>
</ul>
<h5 id="equation-selective-nonlinear-simulations">Equation-selective nonlinear simulations</h5>
<p>The equation-selective nonlinear simulation approach is invoked by setting <code>'method=' 'selective'</code>. In equation-selective nonlinear simulations, the solver tries to find add-factors to user-selected nonlinear equations (ie. equations with <code>=#</code> instead of the equal sign in the model file) in the first-order solution such that the original nonlinear equations hold for simulated trajectories (with expectations replaced with actual leads).</p>
<p>Two numerical approaches are available, controlled by the option <code>'solver='</code>:</p>
<ul>
<li><p>'<code>QaD</code>' - a quick-and-dirty, but less robust method (default);</p></li>
<li><p><code>@fsolve</code>, <code>@lsqnonlin</code> - which are standard Optimization Tbx routines, slower but likely to converge for a wider variety of simulations.</p></li>
</ul>
<h5 id="global-nonlinear-simulations">Global nonlinear simulations</h5>
<p>The global nonlinear simulation approach is invoked by setting <code>'method=' 'global'</code> and is available only in models with no leads (expectations). In global nonlinear simulations, the entire model is solved as a system of nonlinear equations, period by period, using one of the following two Optimization Tbx routines: <code>@fsolve</code> or <code>@lsqnonlin</code> (default).</p>
<h4 id="example">Example</h4>

</body>
<div class="copyright">IRIS Toolbox. Copyright &copy; 2007-2015 IRIS Solutions Team.</div>
</html>
